/**
 * 食物
 */
export class Food {

    /**
     * 食物容器元素
     * @private
     */
    private _element: HTMLElement;

    constructor() {
        this._element = document.getElementById("food")!;
    }

    /**
     * 食物的x坐标
     */
    public get x(): number {
        return this._element.offsetLeft;
    }

    /**
     * 食物的y坐标
     */
    public get y(): number {
        return this._element.offsetTop;
    }

    /**
     * 生成新的食物
     */
    public change(): void {
        let x = Math.round(Math.random() * 29) * 10;
        let y = Math.round(Math.random() * 29) * 10;
        this._element.style.left = x + "px";
        this._element.style.top = y + "px";
    }
}